home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / glibc108.gz / glibc108 / glibc-1.08.1 / inet / arpa / nameser.h < prev    next >
C/C++ Source or Header  |  1993-05-19  |  11KB  |  309 lines

  1. /*
  2.  *    @(#)nameser.h    5.25 (Berkeley) 4/3/91
  3.  *    $Id: nameser.h,v 4.9.1.2 1993/05/17 09:59:01 vixie Exp $
  4.  */
  5.  
  6. /*
  7.  * ++Copyright++ 1983, 1989
  8.  * -
  9.  * Copyright (c) 1983, 1989 Regents of the University of California.
  10.  * All rights reserved.
  11.  * 
  12.  * Redistribution and use in source and binary forms, with or without
  13.  * modification, are permitted provided that the following conditions
  14.  * are met:
  15.  * 1. Redistributions of source code must retain the above copyright
  16.  *    notice, this list of conditions and the following disclaimer.
  17.  * 2. Redistributions in binary form must reproduce the above copyright
  18.  *    notice, this list of conditions and the following disclaimer in the
  19.  *    documentation and/or other materials provided with the distribution.
  20.  * 3. All advertising materials mentioning features or use of this software
  21.  *    must display the following acknowledgement:
  22.  *     This product includes software developed by the University of
  23.  *     California, Berkeley and its contributors.
  24.  * 4. Neither the name of the University nor the names of its contributors
  25.  *    may be used to endorse or promote products derived from this software
  26.  *    without specific prior written permission.
  27.  * 
  28.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  29.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  30.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  31.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  32.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  34.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  37.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  38.  * SUCH DAMAGE.
  39.  * -
  40.  * Portions Copyright (c) 1993 by Digital Equipment Corporation.
  41.  * 
  42.  * Permission to use, copy, modify, and distribute this software for any
  43.  * purpose with or without fee is hereby granted, provided that the above
  44.  * copyright notice and this permission notice appear in all copies, and that
  45.  * the name of Digital Equipment Corporation not be used in advertising or
  46.  * publicity pertaining to distribution of the document or software without
  47.  * specific, written prior permission.
  48.  * 
  49.  * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
  50.  * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
  51.  * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
  52.  * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
  53.  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  54.  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
  55.  * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  56.  * SOFTWARE.
  57.  * -
  58.  * --Copyright--
  59.  */
  60.  
  61. #ifndef _NAMESER_H_
  62. #define    _NAMESER_H_
  63.  
  64. #include <sys/param.h>
  65. #if (!defined(BSD)) || (BSD < 199306)
  66. # include <sys/bitypes.h>
  67. #else
  68. # include <sys/types.h>
  69. #endif
  70. #include <sys/cdefs.h>
  71.  
  72. /*
  73.  * Define constants based on rfc883
  74.  */
  75. #define PACKETSZ    512        /* maximum packet size */
  76. #define MAXDNAME    256        /* maximum domain name */
  77. #define MAXCDNAME    255        /* maximum compressed domain name */
  78. #define MAXLABEL    63        /* maximum length of domain label */
  79.     /* Number of bytes of fixed size data in query structure */
  80. #define QFIXEDSZ    4
  81.     /* number of bytes of fixed size data in resource record */
  82. #define RRFIXEDSZ    10
  83.  
  84. /*
  85.  * Internet nameserver port number
  86.  */
  87. #define NAMESERVER_PORT    53
  88.  
  89. /*
  90.  * Currently defined opcodes
  91.  */
  92. #define QUERY        0x0        /* standard query */
  93. #define IQUERY        0x1        /* inverse query */
  94. #define STATUS        0x2        /* nameserver status query */
  95. /*#define xxx        0x3        /* 0x3 reserved */
  96.     /* non standard - supports ALLOW_UPDATES stuff from Mike Schwartz */
  97. #define UPDATEA        0x9        /* add resource record */
  98. #define UPDATED        0xa        /* delete a specific resource record */
  99. #define UPDATEDA    0xb        /* delete all named resource record */
  100. #define UPDATEM        0xc        /* modify a specific resource record */
  101. #define UPDATEMA    0xd        /* modify all named resource record */
  102.  
  103. #define ZONEINIT    0xe        /* initial zone transfer */
  104. #define ZONEREF        0xf        /* incremental zone referesh */
  105.  
  106. /*
  107.  * Currently defined response codes
  108.  */
  109. #define NOERROR        0        /* no error */
  110. #define FORMERR        1        /* format error */
  111. #define SERVFAIL    2        /* server failure */
  112. #define NXDOMAIN    3        /* non existent domain */
  113. #define NOTIMP        4        /* not implemented */
  114. #define REFUSED        5        /* query refused */
  115.     /* non standard */
  116. #define NOCHANGE    0xf        /* update failed to change db */
  117.  
  118. /*
  119.  * Type values for resources and queries
  120.  */
  121. #define T_A        1        /* host address */
  122. #define T_NS        2        /* authoritative server */
  123. #define T_MD        3        /* mail destination */
  124. #define T_MF        4        /* mail forwarder */
  125. #define T_CNAME        5        /* connonical name */
  126. #define T_SOA        6        /* start of authority zone */
  127. #define T_MB        7        /* mailbox domain name */
  128. #define T_MG        8        /* mail group member */
  129. #define T_MR        9        /* mail rename name */
  130. #define T_NULL        10        /* null resource record */
  131. #define T_WKS        11        /* well known service */
  132. #define T_PTR        12        /* domain name pointer */
  133. #define T_HINFO        13        /* host information */
  134. #define T_MINFO        14        /* mailbox information */
  135. #define T_MX        15        /* mail routing information */
  136. #define T_TXT        16        /* text strings */
  137. #define    T_RP        17        /* responsible person */
  138.     /* non standard */
  139. #define T_UINFO        100        /* user (finger) information */
  140. #define T_UID        101        /* user ID */
  141. #define T_GID        102        /* group ID */
  142. #define T_UNSPEC    103        /* Unspecified format (binary data) */
  143.     /* Query type values which do not appear in resource records */
  144. #define T_AXFR        252        /* transfer zone of authority */
  145. #define T_MAILB        253        /* transfer mailbox records */
  146. #define T_MAILA        254        /* transfer mail agent records */
  147. #define T_ANY        255        /* wildcard match */
  148.  
  149. /*
  150.  * Values for class field
  151.  */
  152.  
  153. #define C_IN        1        /* the arpa internet */
  154. #define C_CHAOS        3        /* for chaos net (MIT) */
  155. #define C_HS        4        /* for Hesiod name server (MIT) */
  156.     /* Query class values which do not appear in resource records */
  157. #define C_ANY        255        /* wildcard match */
  158.  
  159. /*
  160.  * Status return codes for T_UNSPEC conversion routines
  161.  */
  162. #define CONV_SUCCESS 0
  163. #define CONV_OVERFLOW -1
  164. #define CONV_BADFMT -2
  165. #define CONV_BADCKSUM -3
  166. #define CONV_BADBUFLEN -4
  167.  
  168. #ifndef BYTE_ORDER
  169. #define    LITTLE_ENDIAN    1234    /* least-significant byte first (vax, pc) */
  170. #define    BIG_ENDIAN    4321    /* most-significant byte first (IBM, net) */
  171. #define    PDP_ENDIAN    3412    /* LSB first in word, MSW first in long (pdp)*/
  172.  
  173. #if defined(vax) || defined(ns32000) || defined(sun386) || defined(i386) || \
  174.     defined(MIPSEL) || defined(_MIPSEL) || defined(BIT_ZERO_ON_RIGHT) || \
  175.     defined(__alpha__) || defined(__alpha)
  176. #define BYTE_ORDER    LITTLE_ENDIAN
  177. #endif
  178.  
  179. #if defined(sel) || defined(pyr) || defined(mc68000) || defined(sparc) || \
  180.     defined(is68k) || defined(tahoe) || defined(ibm032) || defined(ibm370) || \
  181.     defined(MIPSEB) || defined(_MIPSEB) || defined(_IBMR2) || \
  182.     defined(apollo) || defined(hp9000) || defined(hp9000s300) || \
  183.     defined (BIT_ZERO_ON_LEFT)
  184. #define BYTE_ORDER    BIG_ENDIAN
  185. #endif
  186. #endif /* BYTE_ORDER */
  187.  
  188. #if !defined(BYTE_ORDER) || \
  189.     (BYTE_ORDER != BIG_ENDIAN && BYTE_ORDER != LITTLE_ENDIAN && \
  190.     BYTE_ORDER != PDP_ENDIAN)
  191.     /* you must determine what the correct bit order is for
  192.      * your compiler - the next line is an intentional error
  193.      * which will force your compiles to bomb until you fix
  194.      * the above macros.
  195.      */
  196.   #error "Undefined or invalid BYTE_ORDER";
  197. #endif
  198. /*
  199.  * Structure for query header, the order of the fields is machine and
  200.  * compiler dependent, in our case, the bits within a byte are assignd 
  201.  * least significant first, while the order of transmition is most 
  202.  * significant first.  This requires a somewhat confusing rearrangement.
  203.  */
  204.  
  205. typedef struct {
  206.     u_short    id;        /* query identification number */
  207. #if BYTE_ORDER == BIG_ENDIAN
  208.             /* fields in third byte */
  209.     u_int    qr:1;        /* response flag */
  210.     u_int    opcode:4;    /* purpose of message */
  211.     u_int    aa:1;        /* authoritive answer */
  212.     u_int    tc:1;        /* truncated message */
  213.     u_int    rd:1;        /* recursion desired */
  214.             /* fields in fourth byte */
  215.     u_int    ra:1;        /* recursion available */
  216.     u_int    pr:1;        /* primary server required (non standard) */
  217.     u_int    unused:2;    /* unused bits */
  218.     u_int    rcode:4;    /* response code */
  219. #endif
  220. #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
  221.             /* fields in third byte */
  222.     u_int    rd:1;        /* recursion desired */
  223.     u_int    tc:1;        /* truncated message */
  224.     u_int    aa:1;        /* authoritive answer */
  225.     u_int    opcode:4;    /* purpose of message */
  226.     u_int    qr:1;        /* response flag */
  227.             /* fields in fourth byte */
  228.     u_int    rcode:4;    /* response code */
  229.     u_int    unused:2;    /* unused bits */
  230.     u_int    pr:1;        /* primary server required (non standard) */
  231.     u_int    ra:1;        /* recursion available */
  232. #endif
  233.             /* remaining bytes */
  234.     u_short    qdcount;    /* number of question entries */
  235.     u_short    ancount;    /* number of answer entries */
  236.     u_short    nscount;    /* number of authority entries */
  237.     u_short    arcount;    /* number of resource entries */
  238. } HEADER;
  239.  
  240. /*
  241.  * Defines for handling compressed domain names
  242.  */
  243. #define INDIR_MASK    0xc0
  244.  
  245. /*
  246.  * Structure for passing resource records around.
  247.  */
  248. struct rrec {
  249.     short    r_zone;            /* zone number */
  250.     short    r_class;        /* class number */
  251.     short    r_type;            /* type number */
  252.     u_int32_t    r_ttl;            /* time to live */
  253.     int    r_size;            /* size of data area */
  254.     char    *r_data;        /* pointer to data */
  255. };
  256.  
  257. extern    u_short    _getshort();
  258. extern    u_int32_t    _getlong();
  259.  
  260. /*
  261.  * Inline versions of get/put short/long.  Pointer is advanced.
  262.  * We also assume that a "u_short" holds 2 "chars"
  263.  * and that a "u_int32_t" holds 4 "chars".
  264.  *
  265.  * These macros demonstrate the property of C whereby it can be
  266.  * portable or it can be elegant but never both.
  267.  */
  268. #define GETSHORT(s, cp) { \
  269.     register u_char *t_cp = (u_char*)(cp); \
  270.     (s) = (((u_short)t_cp[0]) << 8) \
  271.         | (((u_short)t_cp[1])) \
  272.         ; \
  273.     (cp) += 2; \
  274. }
  275.  
  276. #define GETLONG(l, cp) { \
  277.     register u_char *t_cp = (u_char*)(cp); \
  278.     (l) = (((u_int32_t)t_cp[0]) << 24) \
  279.         | (((u_int32_t)t_cp[1]) << 16) \
  280.         | (((u_int32_t)t_cp[2]) << 8) \
  281.         | (((u_int32_t)t_cp[3])) \
  282.         ; \
  283.     (cp) += 4; \
  284. }
  285.  
  286. #define PUTSHORT(s, cp) { \
  287.     register u_short t_s = (u_short)(s); \
  288.     register u_char *t_cp = (u_char*)(cp); \
  289.     *t_cp++ = t_s >> 8; \
  290.     *t_cp   = t_s; \
  291.     (cp) += 2; \
  292. }
  293.  
  294. /*
  295.  * Warning: PUTLONG --no-longer-- destroys its first argument.  if you
  296.  * were depending on this "feature", you will lose.
  297.  */
  298. #define PUTLONG(l, cp) { \
  299.     register u_int32_t t_l = (u_int32_t)(l); \
  300.     register u_char *t_cp = (u_char*)(cp); \
  301.     *t_cp++ = t_l >> 24; \
  302.     *t_cp++ = t_l >> 16; \
  303.     *t_cp++ = t_l >> 8; \
  304.     *t_cp   = t_l; \
  305.     (cp) += 4; \
  306. }
  307.  
  308. #endif /* !_NAMESER_H_ */
  309.